package com.zgjkhis.modules.system.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @Author yzq
 * @Description 订单处方
 * @Date 2021/6/23 9:38
 * @Param
 * @return
 **/
@Data
@TableName("his_prescription_info")
public class Info implements Serializable {

    @TableId
    private Long id;
    @ApiModelProperty(value = "处方单号")
    private String infoNo;
    @ApiModelProperty(value = "1-邮寄，2-自提，不传默认是1")
    private Integer isPosted;
    @ApiModelProperty(value = "处方类型1-饮片，2-颗粒，3-打粉, 4-制丸, 5-膏方,中药处方时必填")
    private Integer pstType;
    @ApiModelProperty(value = "处方剂型 如果是饮片，1-自煎，2-代煎；如果是颗粒剂，传 1； 如果是打粉，1-细粉，2-粗粉； 如果是制丸，1-水丸，2-蜜丸，3-大 蜜丸，4-浓缩丸，5-水蜜丸； 如果是膏方，1-瓶装，2-袋装，3-块 装")
    private Integer dosageForm;
    @ApiModelProperty(value = "默认是 1 付，膏方传 1")
    @NotNull(message = "剂量不能为空")
    private Integer num;
    @ApiModelProperty(value = "用药方法 中药处方必填")
    private String takeMethod;
    @ApiModelProperty(value = "医生嘱咐")
    @TableField(exist = false)
    private String docAdvice;
    @ApiModelProperty(value = "订单号")
    private String orderNo;
    @ApiModelProperty(value = "医生id")
    private String docId;
    @ApiModelProperty(value = "医生姓名")
    private String docName;
    @ApiModelProperty(value = "患者名称")
    private String patientName;
    @ApiModelProperty(value = "患者id")
    private String patientId;
    @ApiModelProperty(value = "问诊号")
    private String consultNo;
    @ApiModelProperty(value = "诊断名称")
    @TableField(exist = false)
    private String diagnosisName;
    @ApiModelProperty(value = "用药频次中药处方必填")
    private String frequency;
    @ApiModelProperty(value = "服用要求中药处方必填")
    private String useRequire;
    @ApiModelProperty(value = "处方类型1:中药处方(饮片)，2：成药处方，3：1:中药处方(颗粒剂) 4：输液处方 5：敷贴处方")
    @NotNull(message = "处方类型不能为空")
    @Range(min = 1,max = 3,message = "处方类型错误")
    private Integer prescriptionType;
    @ApiModelProperty(value = "状态0：未支付，1：已支付，2部分退款，3已退款")
    private Integer payStatus;

    @ApiModelProperty(value = "1:普通方子，2：协定方")
    private Integer source;

    private String apiInfoNo;

    private BigDecimal totalPay;
    private BigDecimal processCost;
    private BigDecimal drugCost;
    private BigDecimal courseCost;
    private Integer orderCondition;

    @ApiModelProperty(value = "审方人id")
    private String checkUserId;
    @ApiModelProperty(value = "审方人名称")
    private String checkUser;
    @ApiModelProperty(value = "审方时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date checkTime;
    @ApiModelProperty(value = "调剂用户id")
    private String adjustUserId;
    @ApiModelProperty(value = "调剂用户")
    private String adjustUser;
    @ApiModelProperty(value = "调剂时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date adjustTime;
    @ApiModelProperty(value = "流转金额")
    private BigDecimal cirulationCost;
    @ApiModelProperty(value = "流转订单号")
    private String cirOrderNo;
    @ApiModelProperty(value = "流转处方号")
    private String cirInfoNo;
    @ApiModelProperty(value = "处方用法")
    private String useFlag;
    @ApiModelProperty(value = "药房备注")
    private String phRemark;
    @ApiModelProperty(value = "原始补发处方号")
    private String oldInfoNo;



    /** 创建时间 */
    @TableField(fill= FieldFill.INSERT)
    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "药房id",required = true)
    private String pharmacyId;
    @ApiModelProperty(value = "是否删除：0：否，1：是")
    private Integer deleteFlag;
    @ApiModelProperty(value = "处方详情")
    @TableField(exist = false)
    private List<InfoDrug> infoDrugs;

    public void copy(Info source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }

    public Info copyInfo(String orderNo, String infoNo, Info source){
        Info tempInfo=new Info();
        BeanUtils.copyProperties(source,tempInfo);
        tempInfo.setId(null);
        tempInfo.setInfoNo(infoNo);
        tempInfo.setOrderNo(orderNo);
        tempInfo.setOldInfoNo(source.getInfoNo());
        tempInfo.setTotalPay(BigDecimal.ZERO);
//        tempInfo.setApiInfoNo(null);
        tempInfo.setPayStatus(1);
        tempInfo.setDeleteFlag(0);
        tempInfo.setOrderCondition(1);
        tempInfo.setProcessCost(BigDecimal.ZERO);
        tempInfo.setDrugCost(BigDecimal.ZERO);
        tempInfo.setCourseCost(BigDecimal.ZERO);
        tempInfo.setCheckUserId(null);
        tempInfo.setCheckUser(null);
        tempInfo.setCheckTime(null);
        tempInfo.setAdjustTime(null);
        tempInfo.setAdjustUser(null);
        tempInfo.setAdjustUserId(null);
        tempInfo.setCirulationCost(BigDecimal.ZERO);
        tempInfo.setCirOrderNo(null);
        tempInfo.setCirInfoNo(null);
        tempInfo.setCreateTime(new Date());
        return tempInfo;
    }
}
